import { login } from '@/services';
import { setStorage } from '@/utils';
import { Form, Input, Button, Checkbox, message } from 'antd';
import { history } from 'umi';

const Login = () => {
  const onFinish = async (values: {user: string, pass: string}) => {
    const data = await login(values)
    if (data.msg ==='失败') {
      message.error(data.content);
      return 
    }
    setStorage('userName', values.user)
    history.push('/')
  };

  return (
    <div style={{marginTop: '100px'}}>
      <Form
      name="basic"
      labelCol={{
        span: 8,
      }}
      wrapperCol={{
        span: 8,
      }}
      onFinish={onFinish}
      autoComplete="off"
    >
      <Form.Item
        label="账号"
        name="user"
        rules={[
          {
            required: true,
            message: '输入账号',
          },
        ]}
      >
        <Input />
      </Form.Item>

      <Form.Item
        label="密码"
        name="pass"
        rules={[
          {
            required: true,
            message: '输入密码',
          },
        ]}
      >
        <Input.Password />
      </Form.Item>

      <Form.Item
        wrapperCol={{
          offset: 8,
          span: 16,
        }}
      >
        <Button type="primary" htmlType="submit">
          登录
        </Button>
      </Form.Item>
    </Form>
    </div>
  );
};
export default Login;
